package com.zzyl.service.impl;

import com.zzyl.dto.LoginDto;
import com.zzyl.mapper.SysUserMapper;
import com.zzyl.service.SysUserService;
import com.zzyl.utils.JwtUtil;
import com.zzyl.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description SysUserServiceImpl
 * @Author loe
 * @Date 2024-07-10
 */

@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public UserVo login(LoginDto loginDto) {
        UserVo userVo = sysUserMapper.getUsernameAndPassword(loginDto);
        if (userVo == null) return null;
        Map<String, Object> map = new HashMap<>();
        map.put("id", userVo.getId());
        map.put("username", userVo.getUsername());
        String jwt = JwtUtil.createJWT("itheima", 1, map);
        userVo.setUserToken(jwt);
        return userVo;
    }
}
